<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace api\api\service;


use think\Db;

class UserService
{
	/*
	 * 封装文章评论数收藏等更新方法
	 */
	/**根据条件获取轮播
	 * @param $where
	 * @return array|false|\PDOStatement|string|\think\Collection
	 * @throws \think\db\exception\DataNotFoundException
	 * @throws \think\db\exception\ModelNotFoundException
	 * @throws \think\exception\DbException
	 */
	function setuserparm($userid,$parm,$info)
	{	
		return Db::name('user')->where('id', $userid)->update([$parm => $info]);;
	}
    /**根据条件获取轮播
     * @param $where
     * @return array|false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public static function get_slider_list($where)
    {

        return Db::name('slide_item')->where($where)->order('list_order desc')->select();

    }

    /**根据条件获取分类并排序
     * @param $where
     * @return array|false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     *
     */
    public static function portal_category_select_order_list_order($where)
    {
        return Db::name('portal_category')->where($where)->order('list_order desc')->select();
    }

    /**根据条件获取分类
     * @param $where
     * @return array|false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public static function portal_category_select($where)
    {

        return Db::name('portal_category')->where($where)->select();

    }

    /**根据分类条件查询文章列表
     * @param $where
     * @return array|false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public static function get_portal_by_category_list($where, $page)
    {

        $portal = Db::name('portal_category_post')
            ->alias('post')
            ->join('__PORTAL_POST__ portal', 'post.post_id = portal.id')
            ->where($where)
            ->field('portal.id,portal.user_id,portal.post_title,portal.post_excerpt,portal.thumbnail,portal.published_time')
            ->order('post.list_order')
            ->page($page, 6)
            ->select()
            ->toArray();
        if ($portal) {
            foreach ($portal as $k => $v) {
                $user_nickname = Db::name('user')->field('user_nickname')->where('id', $v['user_id'])->find();
                $portal[$k]['user_nickname'] = $user_nickname['user_nickname'];
                $portal[$k]['published_time'] = get_data_foamt($v['published_time']);
                $portal[$k]['thumbnail'] = cmf_get_image_url($v['thumbnail']);

            }
            //广告封装类
            $ret = getConsultant();
            array_push($portal, $ret);
        }
        return $portal;
    }

    /**获取文章详情
     * @param $where
     * @return array|false|\PDOStatement|string|\think\Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public static function get_portal_detail($where)
    {
        $detail = Db::name('portal_post')
            ->where($where)
            ->find();
        //编辑器内容转换

        return $detail;
    }
	
	/**获取文章详情
	 * @param $where
	 * @return array|false|\PDOStatement|string|\think\Model|null
	 * @throws \think\db\exception\DataNotFoundException
	 * @throws \think\db\exception\ModelNotFoundException
	 * @throws \think\exception\DbException
	 */
	public static function get_areas_id($where,$where2)
	{
		$res = Db::name('areas')->where($where)->find();
		if ($res) {
			return $res['id'];
		} else {
			$res2 = Db::name('areas')->where($where2)->find();
			if ($res2) {
				return $res2['id'];
			}
			return false;
		}
	}
}
